<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>时光桥梁后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/images/logo/favicon.ico"
          type="image/x-icon"/>
    <%--<link rel="shortcut icon" href="${pageContext.request.contextPath}/font/favicon.ico" type="image/x-icon"/>--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/main/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/main/xadmin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/swiper.min.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/login/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/swiper.jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/main/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/api/adminStore.js"></script>

</head>
<body>
<!-- 顶部开始 -->
<div class="container">
    <jsp:include page="../header.jsp"/>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <jsp:include page="../menu.jsp"/>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->

    <div class="page-content">
        <div class="content" style="width: 50%;margin: auto">
            <xblock>
                <button class="layui-btn" onclick="category_add()"><i class="layui-icon">&#xe608;</i>添加</button>
            </xblock>
            <!-- 右侧内容框架，更改从这里开始 -->
            <table class="layui-table">
                <thead>
                <tr>
                    <th>
                        分类名
                    </th>

                    <th>

                    </th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${list}" var="item">
                    <tr>

                        <td>
                                ${item.cname}
                        </td>

                        <td class="td-manage">
                            <!-- 还没想清楚到底是详情好还是修改好 -->
                            <a title="修改" href="javascript:;" onclick="category_edit('${item.cid}')"
                               style="text-decoration:none">
                                <i class="layui-icon">&#xe642;</i>
                            </a>
                            <a title="删除" href="javascript:;" onclick="category_del(this,'${item.cid}')"
                               style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->
<!-- 底部开始 -->
<!-- 		<div class="footer">
			<div class="copyright">Copyright ©2017 x-admin v2.3 All Rights Reserved. 本后台系统由X前端框架提供前端技术支持</div>
		</div> -->
<!-- 底部结束 -->
<!-- 背景切换开始 -->
<jsp:include page="../imagechange.jsp"/>
<!-- 背景切换结束 -->
<!-- 页面动态效果 -->
<script>

    category_del = function(obj, cid) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/category/delServices.do",
                data: {
                    cid: cid
                },
                success: function (s) {
                    if (s.success) {
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg('删除成功', {
                            icon: 1,
                            time: 1000
                        });
                    } else {
                        layer.msg('删除失败,该分类已存在商品', {
                            icon: 1,
                            time: 1500
                        });
                    }
                }
            })
        });
    }


    // 自己写的
    //修改
    category_edit = function (cid) {
        var url = "${pageContext.request.contextPath}/category/toEditCategory.do?cid=" + cid;
        x_admin_show(
            "修改分类信息",
            url,
            "450", "180"
        )
    }

    category_add = function () {
        var url = "${pageContext.request.contextPath}/category/toAddCategory.do";
        x_admin_show(
            "添加分类",
            url,
            "450", "180"
        )
    }

</script>

</body>
</html>
